package com.test.practice.socket.udp;

import lombok.Cleanup;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;

/**
 * udp客户端
 *
 * @Description: udp客户端
 * =======================
 * @Author: Jovi
 * =======================
 * @Date: Created in 2023-02-10
 * =======================
 * @Version: 1.1.2.0
 */
public class UdpClientDemo {

    public static void main(String[] args) throws Exception {

        @Cleanup DatagramSocket ds = new DatagramSocket();

        String str = "你好";

        byte[] datas = str.getBytes();

        InetAddress inetAddress = InetAddress.getLocalHost();

        DatagramPacket dp = new DatagramPacket(
                datas,
                0,
                datas.length,
                inetAddress,
                9090);

        ds.send(dp);
    }
}

